.\"
.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
.\" permission to reproduce portions of its copyrighted documentation.
.\" Original documentation from The Open Group can be obtained online at
.\" http://www.opengroup.org/bookstore/.
.\"
.\" The Institute of Electrical and Electronics Engineers and The Open
.\" Group, have given us permission to reprint portions of their
.\" documentation.
.\"
.\" In the following statement, the phrase ``this text'' refers to portions
.\" of the system documentation.
.\"
.\" Portions of this text are reprinted and reproduced in electronic form
.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
.\" Standard for Information Technology -- Portable Operating System
.\" Interface (POSIX), The Open Group Base Specifications Issue 6,
.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
.\" Engineers, Inc and The Open Group.  In the event of any discrepancy
.\" between these versions and the original IEEE and The Open Group
.\" Standard, the original IEEE and The Open Group Standard is the referee
.\" document.  The original Standard can be obtained online at
.\" http://www.opengroup.org/unix/online.html.
.\"
.\" This notice shall appear on any product containing this material.
.\"
.\" The contents of this file are subject to the terms of the
.\" Common Development and Distribution License (the "License").
.\" You may not use this file except in compliance with the License.
.\"
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
.\" or http://www.opensolaris.org/os/licensing.
.\" See the License for the specific language governing permissions
.\" and limitations under the License.
.\"
.\" When distributing Covered Code, include this CDDL HEADER in each
.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
.\" If applicable, add the following below this CDDL HEADER, with the
.\" fields enclosed by brackets "[]" replaced with your own identifying
.\" information: Portions Copyright [yyyy] [name of copyright owner]
.\"
.\"
.\" Copyright (c) 1997, The Open Group. All Rights Reserved.
.\" Portions Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved.
.\"
.TH BIND 3XNET "Feb 20, 2003"
.SH NAME
bind \- bind a name to a socket
.SH SYNOPSIS
.LP
.nf
\fBcc\fR [ \fIflag\fR ... ] \fIfile\fR ... \fB-lxnet\fR [ \fIlibrary\fR ... ]
#include <sys/socket.h>

\fBint\fR \fBbind\fR(\fBint\fR \fIsocket\fR, \fBconst struct sockaddr *\fR\fIaddress\fR,
     \fBsocklen_t\fR \fIaddress_len\fR);
.fi

.SH DESCRIPTION
.LP
The \fBbind()\fR function assigns an \fIaddress\fR to an unnamed socket.
Sockets created with \fBsocket\fR(3XNET) function are initially unnamed. They
are identified only by their address family.
.sp
.LP
The function takes the following arguments:
.sp
.ne 2
.na
\fB\fIsocket\fR\fR
.ad
.RS 15n
Specifies the file descriptor of the socket to be bound.
.RE

.sp
.ne 2
.na
\fB\fIaddress\fR\fR
.ad
.RS 15n
Points to a \fBsockaddr\fR structure containing the address to be bound to the
socket.  The length and format of the address depend on the address family of
the socket.
.RE

.sp
.ne 2
.na
\fB\fIaddress_len\fR\fR
.ad
.RS 15n
Specifies the length of the \fBsockaddr\fR structure pointed to by the
\fIaddress\fR argument.
.RE

.sp
.LP
The socket in use may require the process to have appropriate privileges to use
the \fBbind()\fR function.
.SH USAGE
.LP
An application program can retrieve the assigned socket name with the
\fBgetsockname\fR(3XNET) function.
.SH RETURN VALUES
.LP
Upon successful completion, \fBbind()\fR returns 0.  Otherwise, \(mi1 is
returned and \fBerrno\fR is set to indicate the error.
.SH ERRORS
.LP
The \fBbind()\fR function will fail if:
.sp
.ne 2
.na
\fB\fBEADDRINUSE\fR\fR
.ad
.RS 17n
The specified address is already in use.
.RE

.sp
.ne 2
.na
\fB\fBEADDRNOTAVAIL\fR\fR
.ad
.RS 17n
The specified address is not available from the local machine.
.RE

.sp
.ne 2
.na
\fB\fBEAFNOSUPPORT\fR\fR
.ad
.RS 17n
The specified address is not a valid address for the address family of the
specified socket.
.RE

.sp
.ne 2
.na
\fB\fBEBADF\fR\fR
.ad
.RS 17n
The \fIsocket\fR argument is not a valid file descriptor.
.RE

.sp
.ne 2
.na
\fB\fBEFAULT\fR\fR
.ad
.RS 17n
The  \fIaddress\fR argument can not be accessed.
.RE

.sp
.ne 2
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 17n
The socket is already bound to an address, and the protocol does not support
binding to a new address; or the socket has been shut down.
.RE

.sp
.ne 2
.na
\fB\fBENOTSOCK\fR\fR
.ad
.RS 17n
The \fIsocket\fR argument does not refer to a socket.
.RE

.sp
.ne 2
.na
\fB\fBEOPNOTSUPP\fR\fR
.ad
.RS 17n
The socket type of the specified socket does not support binding to an address.
.RE

.sp
.LP
If the address family of the socket is AF_UNIX, then \fBbind()\fR will fail if:
.sp
.ne 2
.na
\fB\fBEACCES\fR\fR
.ad
.RS 16n
A component of the path prefix denies search permission, or the requested name
requires writing in a directory with a mode that denies write permission.
.RE

.sp
.ne 2
.na
\fB\fBEDESTADDRREQ\fR\fR
.ad
.br
.na
\fB\fBEISDIR\fR\fR
.ad
.RS 16n
The \fIaddress\fR argument is a null pointer.
.RE

.sp
.ne 2
.na
\fB\fBEIO\fR\fR
.ad
.RS 16n
An I/O error occurred.
.RE

.sp
.ne 2
.na
\fB\fBELOOP\fR\fR
.ad
.RS 16n
Too many symbolic links were encountered in translating the pathname in
\fIaddress.\fR
.RE

.sp
.ne 2
.na
\fB\fBENAMETOOLONG\fR\fR
.ad
.RS 16n
A component of a pathname exceeded \fINAME_MAX\fR characters, or an entire
pathname exceeded \fIPATH_MAX\fR characters.
.RE

.sp
.ne 2
.na
\fB\fBENOENT\fR\fR
.ad
.RS 16n
A component of the pathname does not name an existing file or the pathname is
an empty string.
.RE

.sp
.ne 2
.na
\fB\fBENOTDIR\fR\fR
.ad
.RS 16n
A component of the path prefix of the pathname in \fIaddress\fR is not a
directory.
.RE

.sp
.ne 2
.na
\fB\fBEROFS\fR\fR
.ad
.RS 16n
The name would reside on a read-only filesystem.
.RE

.sp
.LP
The \fBbind()\fR function may fail if:
.sp
.ne 2
.na
\fB\fBEACCES\fR\fR
.ad
.RS 16n
The specified address is protected, and \fB{PRIV_NET_PRIVADOR}\fR is not
asserted in the effective set of the current process.
.RE

.sp
.ne 2
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 16n
The \fIaddress_len\fR argument is not a valid length for the address family.
.RE

.sp
.ne 2
.na
\fB\fBEISCONN\fR\fR
.ad
.RS 16n
The socket is already connected.
.RE

.sp
.ne 2
.na
\fB\fBENAMETOOLONG\fR\fR
.ad
.RS 16n
Pathname resolution of a symbolic link produced an intermediate result whose
length exceeds \fIPATH_MAX\fR.
.RE

.sp
.ne 2
.na
\fB\fBENOBUFS\fR\fR
.ad
.RS 16n
Insufficient resources were available to complete the call.
.RE

.sp
.ne 2
.na
\fB\fBENOSR\fR\fR
.ad
.RS 16n
There were insufficient STREAMS resources for the operation to complete.
.RE

.SH ATTRIBUTES
.LP
See \fBattributes\fR(7) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
Interface Stability	Standard
_
MT-Level	MT-Safe
.TE

.SH SEE ALSO
.LP
.BR sockaddr (3SOCKET),
.BR connect (3XNET),
.BR getsockname (3XNET),
.BR listen (3XNET),
.BR socket (3XNET),
.BR attributes (7),
.BR privileges (7),
.BR standards (7)
